package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.entity.activity.douluodalu.config.DouLuoDaLuConfig;
import com.yanqu.road.entity.activity.douluodalu.config.DouLuoDaLuEventInfo;
import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.douluodalu.DouLuoDaLuModule;
import com.yanqu.road.server.gameplayer.module.player.BagModule;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.Map;

@Cmd(code = Protocol.S_DOU_LUO_DA_LU_EXPLORE,desc = "探索")
public class DouLuoDaLuExploreCmd extends AbstractCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if ((ret = DouLuoDaLuMgr.canEntryActivity(player)) != 0) return;

        if ((ret = DouLuoDaLuMgr.activityInLieHunPeriod()) != 0) return;


        DouLuoDaLuProto.DouLuoDaLuExploreCrossReqMsg.Builder crossReq = DouLuoDaLuProto.DouLuoDaLuExploreCrossReqMsg.newBuilder();
        crossReq.setActivityId(DouLuoDaLuMgr.getActivityInfo().getActivityId());
        long triedStoneNum = player.getModule(DouLuoDaLuModule.class).getTriedStoneNum();
        crossReq.setStoneNum(triedStoneNum);

        // 获取下当前道具的数量
        BagModule bagModule = player.getModule(BagModule.class);
        // 低级宝箱 30001     高级宝箱30002
        crossReq.setLowBoxConsumeCount(bagModule.getUserBagItemCount(Integer.parseInt(DouLuoDaLuMgr.getConfig().getEventInfo(30001).getParam().split("=")[0])));
        crossReq.setHighBoxConsumeCount(bagModule.getUserBagItemCount(Integer.parseInt(DouLuoDaLuMgr.getConfig().getEventInfo(30002).getParam().split("=")[0])));
        player.sendUnionActivityGroupPacket(Protocol.C_DOU_LUO_DA_LU_EXPLORE, crossReq, crossReq.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            DouLuoDaLuProto.DouLuoDaLuExploreRespMsg.Builder respMsg = DouLuoDaLuProto.DouLuoDaLuExploreRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_DOU_LUO_DA_LU_EXPLORE, respMsg);
        }
    }
}
